﻿using ERP.GRX;
using ERP.GRX.Permission;
using ERP.GRX.Permission.DTO;
using ERP.Team.RBAC.GRX;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace ERP.Web.Controllers.RBAC.GRX
{
    public class PermissionController : Controller
    {
        private readonly IPermissionService _permissionService;

        public PermissionController(IPermissionService permissionService)
        {
            _permissionService = permissionService;
        }

        /// <summary>
        /// 权限页面
        /// </summary>
        /// <returns></returns>
        public IActionResult Permission()
        {        
            return View();
        }
        /// <summary>
        ///添加权限页面
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddPermission(PermissionDTO permissionDTO)
        {
            var i=await _permissionService.AddPermission(permissionDTO);
            return i;
        }
        /// <summary>
        /// 查询权限树
        /// </summary>
        /// <param name="ParentId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<PermissionTreeDTO>> GetTreePermission(int ParentId)
        {
            var i = _permissionService.GetTreePermission(ParentId);
            return await i;
        }
        /// <summary>
        ///权限树反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<PermissionDTO> fantianpermission(int id)
        {
            var i=await _permissionService.fantianpermission(id);
            return i;
        }
    }
}
